package com.dys.designpattern.singleton.threadpool;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Author: 疾风
 * @ClassName: TaskUtil
 * @Description: 处理任务的线程工具类
 * @CreateDate: 2024/05/11
 * @Version: v1.0.0
 */
public class TaskUtil {
    private static final ThreadPoolExecutor poolExecutor = ThreadPoolConfig.getInstance();

    public static String submit(Callable callable) throws ExecutionException, InterruptedException {
        String result = "";
        // 使用submit()方法提交任务，execute()方法不接受Callable线程任务
        Future<String> future = poolExecutor.submit(callable);
        // 获取结果
        result = future.get();
        return result;
    }
}
